import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class CompanyManager {
	public static final String COMPANY_TABLE = "Company";
	public static final String COMPANY_ID_COLUMN = "company_id";
	public static final String NAME_COLUMN = "name";
	private static CompanyManager instance = null;
	public static CompanyManager getInstance() throws SQLException {
		if (instance == null) {
			instance = new CompanyManager();
			return instance;
		} else {
			return instance;
		}
	}
	protected CompanyManager() throws SQLException {
		conn = Database.getAccessDBConnection();
	}
	Connection conn = null;
	
	public Company getCompany(int companyId) {
		try {
			Statement stmt = conn.createStatement();
			stmt.execute("SELECT * FROM " + COMPANY_TABLE + " WHERE " + COMPANY_ID_COLUMN + "=" + companyId);
			ResultSet rs = stmt.getResultSet();
			if (!rs.next()) {
				stmt.close();
				return null;
			} else {
				Company c = new Company(rs);
				stmt.close();
				return c;
			}
		} catch (SQLException e) {
			return null;
		}
	}
}
